﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using game.character;
using lumo.display.object2D;
using lumo;

namespace game.display.object2d
{
    /// <summary>
    /// 
    /// </summary>
    public class SpriteCharacter : Sprite, IUpdatable, game.display.effect.IShadowable
    {
        // Character.
        GameCharacter Character;

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="Character">The character</param>
        public SpriteCharacter(GameCharacter Character) :
            base(Character.Texture)
        {
            this.Character = Character;
        }

        /// <summary>
        /// Update this sprite.
        /// </summary>
        /// <param name="component"></param>
        public void Update(LumoComponent component)
        {
            // Set the position.
            this.Texture  = Character.Texture;
            this.Position = Character.ScreenPosition;
            this.Origin   = Character.ScreenOrigin;
            this.Radians  = Character.ScreenRadians;
            this.SourceRectangle = Character.SourceRectangle;

            this.SpriteEffects = Microsoft.Xna.Framework.Graphics.SpriteEffects.None;
            if (Character.ScreenMirrorX)
                this.SpriteEffects |= Microsoft.Xna.Framework.Graphics.SpriteEffects.FlipHorizontally;
            if (Character.ScreenMirrorY)
                this.SpriteEffects |= Microsoft.Xna.Framework.Graphics.SpriteEffects.FlipVertically;
        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
            if ((Character is IShootable) && ((Character as IShootable).BulletManager != null))
                (Character as IShootable).BulletManager.Draw(spriteBatch);
        }

        /// <summary>
        /// 
        /// </summary>
        public bool CastShadow
        {
            get { return Character.ScreenCastShadow; }
        }

        /// <summary>
        /// 
        /// </summary>
        public bool HighPriority
        {
            get { return Character.ScreenHighPriority; }
        }
    }
}
